import random
from string import ascii_letters,digits
def randpass(n=8):
    result = ""  # 用于保存最终的密码
    for i in range(n):  # 已知次数循环用for，range控制循环次数
        p = random.choice(ascii_letters + digits)#随机一位密码
        result += p  # result = result + p
    return result
if __name__ == "__main__":
    pwd = randpass()  # n=8
    print(pwd)
    pwd = randpass(10)  # n=10
    print(pwd)